package fr.sedoo.sssdata.server.sos.request;

import net.opengis.swes.x20.DescribeSensorDocument;
import net.opengis.swes.x20.DescribeSensorType;
import fr.sedoo.sssdata.server.sos.XmlBeansUtils;


public class SosIsPresentRequest extends SosRequest {
	
	private boolean present = false;
	
	public SosIsPresentRequest(String sensorId) {
		
		DescribeSensorDocument describeSensorDoc = DescribeSensorDocument.Factory.newInstance();
		DescribeSensorType describeSensor = describeSensorDoc.addNewDescribeSensor();
		describeSensor.setService("SOS");
		describeSensor.setVersion("2.0.0");
		describeSensor.setProcedure(sensorId);
		describeSensor.setProcedureDescriptionFormat("http://www.opengis.net/sensorML/1.0.1");
		setRequest(XmlBeansUtils.toString(describeSensorDoc));
	}

	@Override
	protected boolean validate(String rawXml) 
	{
		if (rawXml.indexOf("exceptionCode=\"InvalidParameterValue\"")>0)
		{
			setPresent(false);
			return true;
		}
		else if (super.validate(rawXml) == false)
		{
			return false;
		}
		else
		{
			setPresent(true);
			return true;
		}
	}

	public boolean isPresent() {
		return present;
	}

	public void setPresent(boolean present) {
		this.present = present;
	}
	
	

}
